;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Report.WarrantyTracking", [])
        .controller("WarrantyTrackingCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$filter", "$timeout", "UserContextService", "$stateParams", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $filter, $timeout, UserContextService, $stateParams) {
            $scope.markInfo = {
                curRow: -1
            };

            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };

            $scope.exportParam = {
                allUrl: ybHttp.RequestUrl("device", "/report/exportThreeGuaranteesReportList")
            };

            $scope.toolbarConfig = {
                showAdvanceSearch: false,
                showColConfig: false,
            };
            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };

            $scope.condition = {};
            $scope.dataList = [];

            $scope.tbConf = {
                scrollWidth: 2600,
                tableCol: [
                    {
                        name: "客户名称",
                        dataField: "customerName",
                        width: 140,
                        isShow: true
                    },
                    {
                        name: "三包申请单号",
                        dataField: "purchaseNo",
                        width: 140,
                        isShow: true
                    },
                    {
                        name: "三包出库单号",
                        dataField: "guaranteesOutNo",
                        width: 140,
                        isShow: true
                    },
                    {
                        name: "交接单号",
                        dataField: "deliveryBillNo",
                        width: 140,
                        isShow: true
                    },
                    {
                        name: "零件编号",
                        dataField: "materialsNo",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "零件中文名",
                        dataField: "materialsDes",
                        width: 140,
                        isShow: true
                    },
                    {
                        name: "订单总数",
                        dataField: "purchaseQty",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "已发数量",
                        dataField: "outQty",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "出库数量",
                        dataField: "deliveryQty",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "实际出库数量",
                        dataField: "realOutQty",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "出库状态",
                        dataField: "outLocationStatusShow",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "发运状态",
                        dataField: "deliveryDesc",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "CRM单据号",
                        dataField: "crmOrder",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "服务信息单号",
                        dataField: "serviceNo",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "国家和地区",
                        dataField: "country",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "备注",
                        dataField: "note",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "申请时间",
                        dataField: "applicationDateShow",
                        width: 140,
                        isShow: true
                    },
                ]
            };

            $scope.reset = function () {
                $scope.condition = {};
            };

            $scope.search = function (curpage) {
                getDataList(curpage);
            };

            $scope.selectRow = function (index) {
                $scope.markInfo.curRow = index;
            };

            $scope.checkDate = function (obj, startFiled, endFiled) {
                var timeFormatObj = ybWidget.CheckDate(obj[startFiled], obj[endFiled]);
                if (!!timeFormatObj.tStart) {
                    obj[startFiled] = timeFormatObj.tStart;
                }
                if (!!timeFormatObj.tEnd) {
                    obj[endFiled] = timeFormatObj.tEnd;
                }
            };

            function getDataList(curPage) {
                $scope.markInfo.curRow = -1;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }

                var service = "device";
                var reqUrl = "/report/threeGuaranteesReportList";
                var param = {
                    pageNum: $scope.pageInfo.curPage,
                    pageSize: $scope.pageInfo.pageSize,
                    filters: angular.copy($scope.condition)
                };
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.applicationDateShow = $filter("YbDate")(item.applicationDate, 'yyyy-MM-dd HH:mm:ss');
                        item.outLocationStatusShow = $filter("OutboundStatus2")(item.outLocationStatus);
                    });
                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                });
            }

            (function () {
                getDataList();
            })();
        }])
    ;
})(window, window.angular);